package com.taptech.doufu.constant;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Environment;

import com.taptech.doufu.bean.MyAccount;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Constant
{

    public final static boolean DEBUG_FLAG = true;
    public static final String RUNNING = "running";
    public static boolean activityRun;
    public final static String TAG = "Doufu";

    public static final String DIAOBAO_KEY = "21#D4dfge35^*0a]s[df";


    public static final String BASE_URL = "http://" + Constant.HOST_NAME +"/";

    public static final String DB_NAME = "Doufu.db";
    public static final int DB_VERSION = 12;

    public static boolean exitsSDCard = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    public static final int PAGE_SIZE_6 = 6;
    public static final int PAGE_SIZE_10 = 10;
    public static final int PAGE_SIZE_12 = 12;
    public static final int PAGE_SIZE_20 = 20;
    public static final int PAGE_SIZE_30 = 30;
    public static final int PAGE_SIZE_100 = 100;
    public static MyAccount myAccount;


    public static final int SEPARATE_RETURN_DATA_NUMBER = 20;
    // wx
//    public final static String WX_APP_ID = "wxa34b28425cdbe6a3";
    public final static String WX_APP_ID = "wxa4be7882bc9c2109";


    public static int mMaxThumbnailWidth = 120;

    public static int mMaxThumbnailHeight = 120;

    public static int mScreenType = ScreenSplashType.DEVICE_ANDROID_MDPI;

    public static int footFlag;
    /**
     * 新浪微博 第三方应用 APP_KEY
     */
    public static final String APP_KEY = "3936487439";
    public static final String REDIRECT_URL = "http://www.sharereader.cn";
    /**
     * 当前 DEMO 应用的回调页，第三方应用可以使用自己的回调页。
     * 注：关于授权回调页对移动客户端应用来说对用户是不可见的，所以定义为何种形式都将不影响， 但是没有定义将无法使用 SDK 认证登录。
     * 建议使用默认回调页：https://api.weibo.com/oauth2/default.html
     */

    public static final int STATUS_SUCCESS = 0;

    public static final int STATUS_REPEAT_PRAISE = 18;

    public static final int STATUS_TIME_OUT = -500;

    public static final int COMMENT_SIZE = 20;

    // 腾讯三方应用 APP_ID
    public static final String APP_ID = "1110978196";
    public static final String SCOPE = "get_user_info,get_simple_userinfo,get_user_profile,get_app_friends," + "add_share,add_topic,list_album,upload_pic,add_album,set_user_face,get_vip_info,get_vip_rich_info,get_intimate_friends_weibo,match_nick_tips_weibo";
    public static final String PAGE_INDEX = "page_index";
    public static final String DATA = "data";
    public static final String IS_SELF = "is_self";
    public static final String IS_NEWSTCARTOON = "is_newstcartoon";
    public static final String USER_ID = "userId";
    public static final String TYPE = "type";
    public static final String NOVEL_NAME = "novel_name";
    public static final String PRE_COLLECT_COUNT = "pre_collect_count";
    public static final String NOVEL_ID = "novel_id";
    public static final String GROUP_ID = "group_id";
    public static final String TOPIC_ID = "topic_id";
    public static final String UID = "uid";
    public static final String RECORDID = "record_id";
    public static final String USERNICKNAME = "user_nickname";
    public static final String MOBILE = "mobile";
    public static final String EMAIL = "email";
    public static final String SIGNATURE = "user_signature";
    public static final String USER_HEAD_IMG = "user_head_img";
    public static final String NAME = "name";
    public static final String NICKNAME = "nickname";
    public static final String SOCIAL_TYPE = "social_type";
    public static final String REGTYPE = "regtype";
    public static final String LOGIN_TYPE = "login_type";
    public static final String LOGIN_COUNT = "login_count";
    public static final String GROUP = "group";
    public static final String DESC = "desc";
    public static final String GROUP_NAME = "group_name";
    public static final String RESULT = "result";
    public static final String INVITATION_CODE = "invitation_code";
    public static final String ARTICLE_ID = "article_id";
    public static final String HAS_FAV = "has_fav";
    public static final String MONTH_TICKET_SUM = "month_ticket_sum" ;
    public static boolean isHasFav = false;
    public static final String KEY_SEARCH_TAG = "seartch_tag";
    public static final String RANK_FALG = "rank_flag";
    public static final String ARTICLE_NOVELID = "novel_id";
    public static final String ARTICLE_ITEM = "article_item";
    public static final String ARTICLE_TITLE = "article_title";
    public static final String COMMENT = "comment";
    public static final String OP_TYPE = "op_type";
    public static final String IMAGE = "IMAGE";
    public static final String OBJECT_TYPE = "object_type";
    public static final String LAST = "last";
    public static final String LIST = "list";
    public static final String TITLE = "title";
    public static final String ID = "id";
    public static final String KEYWORD = "keyword";
    public static final String FROM = "from";
    public static final String URL = "URL";
    public static final String JS_URL = "JS_URL";
    public static final String HELP_URL = "help_url";
    public static final String ARTICLEID = "articleid";
    public static final String AD_ID = "ad_id";
    public static final String DATE = "date";
    public static final String DOMAIN = "domain";
    public static final String SCREENINFO = "screenInfo";
    public static final String WIDTH = "width";
    public static final String HEIGHT = "height";
    public static final String MAIN = "main";
    public static final String TOPIC = "topic";
    public static final String DIAOBAO_IMAGE_HOST = "http://imgold2.doufu.la/";
    public static final String COMMENT_TODAY_FULL = " 今日评论分已赚满~";
    public static final String REPLY_TODAY_FULL = " 今日回复分已赚满~";
    public static final String SWEEP_ID = "sweep_id";
    public static final String NOVEL_HOME_BEAN = "novel_homebean";
    public static final String SWEEP_FLOWER_USER = "flower_user";
    public static final String NOTE_ID = "note_id";
    public static final String CARTOON_ID = "cartoon_id";
    public static final String NOVEL_FLOWER_USER = "novel_flower_user";
    public static final String FLAG = "flag";
    public static final String FLOWERSHOWFLAG = "flowershowflag";
    public static final String FLOWER_SHOW = "flower_show";
    public static final String FLOWER_HIDE = "flower_hide";
    public static final String AUTHOR_ID = "author_id";
    public static final String ABLE_TO_DOWNLOAD = "able_to_download";
    public static final String COMPETENCE_DIALOG_NOVEL_SHOW = "competence_dialog_novel_show";
    public static final String COMPETENCE_DIALOG_DRAW_SHOW = "competence_dialog_draw_show";
    public static final String COMPETENCE_DIALOG_COS_SHOW = "competence_dialog_cos_show";
    public static final String POSITION = "position";

    // 没有私信，只有反馈的管理员id名单
    public static final Set<String> managerIdSet = new HashSet<>(Arrays.asList(new String[]{"50100", "931204","50102"}));

    /**
     * 专题
     */
    public static final int CONTENT_TYPE_TOPIC = 5;
    /**
     * 小说章节
     */
    public static final int CONTENT_TYPE_WORDS = 6;
    /**
     * 用户
     */
    public static final int CONTENT_TYPE_USER = 12;

    public static final int OBJECT_TYPE_LETTER = 14; // 私信
    public static final int OBJECT_TYPE_NOTIFY = 15; // 通知
    /**
     * 普通帖
     */
    public static final int OBJECT_TYPE_USERS_TOPIC = 16;
    public static final int OBJECT_TYPE_LIVE_TOPIC = 17; // 直播帖
    /**
     * 小说
     */
    public static final int OBJECT_TYPE_NOVEL = 18;
    public static final int OBJECT_TYPE_ANSWER = 19; // 腐化度测试
    public static final int OBJECT_TYPE_NOVEL_DETAILS = 22; // 章节详情
    public static final int OBJECT_TYPE_BROWSE = 24;// 跳转到内部网页的类型
    public static final int OBJECT_TYPE_EASY_WEBVIEW = 27;// 跳转到外部网页的类型

    /**
     * 小说摘要
     */
    public static final int OBJECT_TYPE_DIGEST = 28;
    /**
     * 文评
     */
    public static final int OBJECT_TYPE_SWEEP = 29;
    /**
     * 日志
     */
    // 42绘画 43 COS
    public static final int OBJECT_TYPE_NOTE = 41;
    public static final int OBJECT_TYPE_DRAW = 42;
    public static final int OBJECT_TYPE_COS = 43;
    //cp
    public static final int OBJECT_TYPE_CP = 38;
    public static final int OBJECT_TYPE_NOVEL_SECTION_DRAFT = 44; // 小说章节草稿
    public static final int OBJECT_TYPE_CARTOON = 45;
    public static final int OBJECT_TYPE_CHATNOVEL = 66;

    public static final int OBJECT_TYPE_TYRANT = 200;


    public static final int OBJECT_TYPE_TAG_COLLECT = 38;
    /**
     * 我的收藏
     */
    public static final int OBJECT_TYPE_FAVORITE = 32;
    /**
     * 专题
     */
    public static final int OBJECT_TYPE_ALBUMS = 39;
    public static final int OBJECT_TYPE_BOOKLIST = 63;

    /**
     * WEEX
     */
    public static final int OBJECT_TYPE_WEEX = 64;

    /**
     * 广告
     */
    public static final int OBJECT_TYPE_AD = 68;

    // 评论
    public static final int OP_TYPE_COMMENT = 1;
    public static final int OP_TYPE_UGC = 6; // UGC
    public static final int OP_TYPE_COLLECT = 10;// 收藏

    public static final int OP_TYPE_REPLY = 13;// 回复
    public static final int OP_TYPE_REPLY_REPLY = 15;// 回复的回复
    public static final int OP_TYPE_REVIEW = 17;// 审核
    public static final int OP_TYPE_INVITE_POINT = 23;// 邀请积分
    public static final int OP_TYPE_SYSTEM = 43;// 系统通知
    public static final int NOTIFY_TYPE_ALL = 0;// 多种通知
    public static final String INVITE_GROUP_LEFT = "我加入了豆花App“XXX”，里面好多有意思的话题和小伙伴，三观都重塑了！哈哈你快过来拯救我吧！#豆花圈子#豆花，女性向创作社区  @豆花。注册完填写邀请码【";
    public static final String INVITE_LEFT = "一看就知道你腐的潜力无穷，太适合和我一起玩这个了！豆花，女性向创作社区！注册完请填写邀请码【";
    public static final String INVITE_RIGHT = "】官网下载：" + Constant.DOWN_URL_WB;
    public static final String INVITE_RIGHT_WEIXIN = "】官网下载：" + Constant.DOWN_URL_WX;
    ;

    public static final String APPAID = "3";// 3：豆花，4：星饭，5：tfboys
    public static final String DOWN_URL_WX = "http://a.app.qq.com/o/simple.jsp?pkgname=com.taptech.doufu";
    public static final String DOWN_URL_WB = "https://api.doufu.la/apk_rise/down?channel=wb";
    public static final String DOWN_URL_DX = "https://api.doufu.la/apk_rise/down?channel=dx";
    public static final String DOWN_URL_YJ = "https://api.doufu.la/apk_rise/down?channel=yj";
    public static final String DOWN_URL_QQ = "https://api.doufu.la/apk_rise/down?channel=qq";

    public static final String LOGO_URL = "http://weex.doufu.la/images/icon_share.jpg";
    public static final String SHARE_IMAG_URL = "http://weex.doufu.la/images/icon_share.jpg";

    public static class ScreenSplashType
    {
        public final static int DEVICE_ANDROID_LDPI = 4;
        public final static int DEVICE_ANDROID_MDPI = 5;
        public final static int DEVICE_ANDROID_HDPI = 6;
        public final static int DEVICE_ANDROID_XDPI = 7;
    }


    public static class ImageSampleSize
    {
        public final static int SAMPLE_SIZE_LDPI = 5;
        public final static int SAMPLE_SIZE_MDPI = 4;
        public final static int SAMPLE_SIZE_HDPI = 3;
        public final static int SAMPLE_SIZE_XDPI = 2;
    }

    public static class WXData
    {
        public final static int THUMB_WIDTH_SIZE = 100;
        public final static int THUMB_HEIGHT_SIZE = 100;
        public final static int PENG_YOU_QUAN_MIN_VERSION_CODE = 0x21020001;
    }

    public static class OffLineArticleInfo
    {
        public final static String title = "title";
        public final static String author = "author";
        public final static String icon = "icon";
        public final static String time = "time";
        public final static String refHtml = "refHtml";
    }
    /**
     * 首页图片卡片类型
     */
    public static class MainHomeImageCardType{
        public final static int JUMP_TYPE_INSIDE_WEBVIEW = 4001;   //内部链接
        public final static int JUMP_TYPE_OUTSIDE_WEBVIEW  = 4002;  //外部链接
        public final static int JUMP_ALBUM  = 4003;   //专辑
        public final static int JUMP_TYPE_WEEX  = 4080;  //Weex
        public final static int JUMP_IP  = 69;  //IP合作
    }

    public static class ShareDataType{
        public final static int SHARE_DATA_TYPE_TEXT = 1;
        public final static int SHARE_DATA_TYPE_IMAGE = 2;
    }

    public static class ShareChannel
    {
        public final static String qq = "qq";
        public final static String qZone = "qzone";
        public final static String SinaWeibo = "sina";
        public final static String TecentWeibo = "txweibo";
        public final static String Weixin = "weixin";
        public final static String pengyouquan = "pengyouquan";
        public final static String other = "other";
    }

    public static class WeMediaCache {
        public final static String CACHE_FILE_ALL_WE_MEDIA_TITLE = "allwemediatitle.cache";
        public final static String CACHE_FILE_CHOOSE_WE_MEDIA = "choosewemedia.cache";
        public final static String CACHE_FILE_CHOOSE_ARTICLE = "choosearticle.cache";

    }

    public class ImageType
    {
        public final static String IMAGE_BMP_1 = "bmp";
        public final static String IMAGE_BMP_2 = "dib";
        public final static String IMAGE_JPEG_1 = "jpg";
        public final static String IMAGE_JPEG_2 = "jpeg";
        public final static String IMAGE_JPEG_3 = "jpe";
        public final static String IMAGE_JPEG_4 = "jfif";
        public final static String IMAGE_PNG = "png";
    }

    public class Settings
    {
        public final static String NAME = "settings";
        public final static String PUSH = "push";
        public final static int VALUE_FONT_SIZE_TYPE_SMALL = 0;
        public final static int VALUE_FONT_SIZE_TYPE_MIDDLE = 1;
        public final static int VALUE_FONT_SIZE_TYPE_BIG = 2;

        public final static int VALUE_BRIGHTNESS_MODE_AUTO = 0;
        public final static int VALUE_BRIGHTNESS_MODE_MANUAL = 1;

        public static final String PADDING_LEFT = "padding_left";
        public static final String PADDING_RIGHT = "padding_right";
        public static final String FONT_SIZE = "font_size";
    }

    public class ReadAnimationType{
        public final static int HorizontalCover = 1;
        public final static int VerticalScroll = 2;
        public final static int LikeBook = 3;
        public final static int NONE = 4;
    }

    public class ReadIndentType{
        public final static int ALIGN = 1;//对齐
        public final static int FORMAT = 2;//缩进
    }

    public class ReadAutoPlayType{
        public final static int LINE = 1;//逐行扫描
        public final static int PAGE = 2;//按页翻动
    }


    public class ReadSpace {
        public final static float TIGHT = 0.5f;//紧凑
        public final static float NORMAL = 0.7f;//正常
        public final static float LOOSE = 1.0f;//松散
    }


    public class SettingsSplash
    {
        /* Verison 1.1 */
        public final static String NAME = "settings_splash";

        public final static String FIELD_TITLE = "title";
        public final static String FIELD_URL = "url";
        public final static String FIELD_DESCRIPTION = "description";
        public final static String FIELD_SPONSORED_LINK = "sponsored_link";
    }

    public class SettingsRefreshTime
    {
        /* Verison 1.1 */
        public final static String NAME = "settings_refresh_time";
    }


    /**
     * 测试帐号 tttt@qq.com 111111
     */
    public static final String HOST_END_PAST = "douhuawenxue.com";
    public static final String OLD_HOST_NAME = "api.doufu.la";
//    public static final String HOST_NAME = "api.doufu.douhuayuedu.com";
    public static final String HOST_NAME = "api."+HOST_END_PAST;
    public static final String HOST_NAME_SECOND = "http://" + HOST_NAME;

    /**
     * 替换host
     * @param url
     * @return
     */
    public static String changeUrlHost(String url) {
        if (url != null) {
//            url = url.replace("doufu.la", "doufu.douhuayuedu.com");
            url = url.replace("doufu.la", HOST_END_PAST);
            url = url.replace("doufuyuedu.com", HOST_END_PAST);
            url = url.replace("doufu.douhuayuedu.com", HOST_END_PAST);
        }
        return url;
    }

    public class Guide {
        public static final String NAME = "guide";
        public static final String VERSION_CODE = "version_code";
    }

    public class NovelCreate
    {
        public static final String NAME = "novel_create";
        public static final String NOVELID = "novelId";
        public static final String TITLE = "title";
        public static final String CONTENT = "content";
        public static final String AUTHORSAY = "authorSay";
    }

    public class NovelDrafs
    {
        public static final String NAME = "novel_drafs";
        public static final String TITLE = "title";
        public static final String CONTENT = "content";
        public static final String AUTHORSAY = "authorSay";
    }

    public class NovelSend {
        public static final String NAME = "novel_send";
        public static final String TITLE = "title";
        public static final String CONTENT = "content";
        public static final String AUTHORSAY = "authorSay";
    }

    public class Version {
        public static final String NAME = "version";
        public static final String VERSION = "oldVersion";
    }


    public class DayNight
    {
        public static final String NAME = "day_night_mode";
        public static final String IS_DAY = "day_or_night";
        public static final String DAY = "day";
        public static final String IS_NIGHT = "is_night";
    }

    public class Traffic
    {
        public static final String NAME = "traffic";
    }

    public class OffLineSTATUS
    {
        public static final int DOWN_START = 0;
        public static final int DOWN_SUCCESS = 1;
        public static final int DOWN_ING = 2;
    }

    public static String getErrorTips(int status)
    {
        String tips = "";
        switch (status)
        {
            case Constant.STATUS_REPEAT_PRAISE:
                tips = "你已经赞过了";
                break;

            default:
                break;
        }

        return tips;
    }



    public static String loadingFail = "网络异常，请检查网络后再试";
    public static String loading = "彩虹万岁，等等无罪";
    public static String[] loadings = {
            "拒绝盗文盗图和抄袭",
            "贴图要注明作者哟 (━(ﾟ∀ﾟ)━!",
            "一旦打广告，立马被封号( •̀∀•́ ) ",
            "到别人地盘拆别人CP菊花会爆炸哟！（￢з￢） ",
            "首次发文会在3天内审核，通过则公开显示",
            "无意义刷帖，会被禁言哦~",
            "编辑小说后，记得存稿哦~",
            "献花支持5秒连击，不要只戳一下啦~>_<~+"
    };
    public static String sharedPre_novel = "novel_last_look";
    public static String sharedPre_push = "personal_push_status";
    public static boolean IS_TRAFFIC_MODE = false;
    public static String starLevel_01 = "重踩";
    public static String starLevel_02 = "轻踩";
    public static String starLevel_03 = "已阅";
    public static String starLevel_04 = "小推";
    public static String starLevel_05 = "强推";
    // @请求
    public static final int AT_WRITE = 1001;
    public static final int AT_CLICK = 1002;
    public static final int AT_RESULI = 1003;
    public static final int TAG_ADD_FROM_UGC = 1004;

    public static class AppDir
    {
        public final static String DIR_HOME = Environment.getExternalStorageDirectory().getPath() + "/Doufu/";
        public final static String DIR_TMP = AppDir.DIR_HOME + "tmp/";
        public final static String DIR_CACHE = AppDir.DIR_HOME + "cache/";

        public final static String DIR_CACHE_SPLASH = DIR_CACHE + "splash/";
        public final static String DIR_CACHE_MAIN = DIR_CACHE + "main/";
        public final static String DIR_CACHE_ARTICLE = DIR_CACHE + "article/";
        public final static String DIR_CACHE_IMAGE = DIR_CACHE + "image/";
        public final static String DIR_CACHE_PAPER = DIR_CACHE + "paper/";
        public final static String DIR_OFFLINE_DATA = DIR_CACHE + "offline_data/";
        public final static String FILE_CACHE_DATA = DIR_CACHE + "data";
        public final static String FILE_CACHE_DATA_MAIN = DIR_CACHE + "data/main/";

        public static File getScreenSplash(String screenSplash)
        {
            return new File(DIR_CACHE_SPLASH + screenSplash);
        }
    }


    /**
     * 获取版本号
     *
     * @param context
     * @return
     */
    public static int getVersionCode(Context context)// 获取版本号(内部识别号)
    {
        try
        {
            PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return pi.versionCode;
        } catch (NameNotFoundException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return 0;
        }
    }


    public final static float imagViewAlpha = 0.8f;


}
